home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / 99 Bottles hack / MyUtils / MySpeechSynthesis.p < prev    next >
Encoding:
Text File  |  2001-06-23  |  1.3 KB  |  71 lines

  1. unit MySpeechSynthesis;
  2.  
  3. interface
  4.  
  5.     uses
  6. {$IFC UNDEFINED THINK_PASCAL}
  7.         Types, 
  8. {$ELSEC}
  9.         InterfacesUI, {Glue for 4.0.2 without UPI!}
  10. {$ENDC}
  11.         DialogUtils, Speech;
  12.  
  13.     procedure MyInitSpeech (sayEnabled: Boolean);
  14. { Speak arbitrary text, optionally sets a stat text dialog with the text }
  15.     procedure Say (theStr: Str255;
  16.                                     dontInterrupt: Boolean;
  17.                                     dlg: DialogPtr;
  18.                                     item: Integer);
  19.     function MySpeechBusy: Boolean;
  20.  
  21. implementation
  22.  
  23.     var
  24.         gCanSpeak: Boolean;
  25.  
  26.     procedure MyInitSpeech;
  27.         var
  28.             err: OSErr;
  29.             result: LongInt;
  30.     begin
  31.         gCanSpeak := false;
  32.         err := Gestalt(gestaltSpeechAttr, result);
  33.         if (err = noErr) then
  34.             if BTst(result, gestaltSpeechMgrPresent) then
  35.                 gCanSpeak := true;
  36.  
  37.         if sayEnabled then
  38.             Say('Speech synthesis enabled', false, nil, 0);
  39.     end; { MyInitSpeech }
  40.  
  41.     procedure Say (theStr: Str255;
  42.                                     dontInterrupt: Boolean;
  43.                                     dlg: DialogPtr;
  44.                                     item: Integer);
  45.         var
  46.             oe: OSErr;
  47.     begin
  48.         if dontInterrupt then
  49.             while MySpeechBusy do
  50.                 ;
  51.         if gCanSpeak then
  52.             oe := SpeakString(theStr);
  53.         if dlg <> nil then
  54.             if item > 0 then
  55.                 SetTextDItem(dlg, item, theStr);
  56.     end;
  57.  
  58.     function MySpeechBusy: Boolean;
  59.     begin
  60.         if gCanSpeak then begin
  61.             if SpeechBusy > 0 then
  62.                 MySpeechBusy := true
  63.             else
  64.                 MySpeechBusy := false;
  65.         end
  66.         else
  67.             MySpeechBusy := false;
  68.     end;
  69.  
  70.  
  71. end.